package cn.qidisoft.edu.hzjt.service.zyc.impl;

import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.qidisoft.core.common.code.QdfRespCode;
import cn.qidisoft.core.common.exception.dao.DBException;
import cn.qidisoft.core.common.log.LoggerAdapter;
import cn.qidisoft.core.common.log.LoggerAdapterFactory;
import cn.qidisoft.core.common.pagination.Page;
import cn.qidisoft.core.common.pagination.PaginationBean;
import cn.qidisoft.edu.hzjt.dao.zyc.ResearchProjectAuditingMapper;
import cn.qidisoft.edu.hzjt.model.zyc.Department;
import cn.qidisoft.edu.hzjt.model.zyc.ResearchProject;
import cn.qidisoft.edu.hzjt.model.zyc.TeachingGroup;
import cn.qidisoft.edu.hzjt.service.zyc.IResearchProjectAuditingService;
import cn.qidisoft.edu.hzjt.utils.LogType;

@Service
@Transactional
public class ResearchProjectAuditingServiceImpl implements IResearchProjectAuditingService {
	protected static final LoggerAdapter LOGGER = LoggerAdapterFactory.getLogger(LogType.HZJT_LOGGER.val);
	@Autowired
	private ResearchProjectAuditingMapper researchProjectAuditingMapper;

	@Override
	public PaginationBean<ResearchProject> queryResearchProjectAuditingPageList(Map<String, Object> queryMap,
			Page page) {
		try {

			int c = researchProjectAuditingMapper.queryResearchProjectAuditingPageCount(queryMap);
			int totalRecords = 0;
			totalRecords = (int) c;

			PaginationBean<ResearchProject> pageHolder = new PaginationBean<ResearchProject>(page, totalRecords);

			List<ResearchProject> resultList = researchProjectAuditingMapper.queryResearchProjectAuditingPageList(queryMap,
					new RowBounds((pageHolder.getCurrentPage() - 1) * pageHolder.getPageSize(),
							pageHolder.getPageSize()));
			pageHolder.setPageList(resultList);
			return pageHolder;
		} catch (Exception e) {
			e.printStackTrace();
			LOGGER.error("queryStudentDemoPageList [{}] error," + this.getClass().getName() + "=[{}]",
					this.getClass().getName(),
					ToStringBuilder.reflectionToString(queryMap, ToStringStyle.SHORT_PREFIX_STYLE));
			throw new DBException(QdfRespCode.QDF_020002.getCode(), QdfRespCode.QDF_020002.getMsg(), e);
		}
	}

	@Override
	public List<ResearchProject> queryResearchProjectAuditingList(Map<String, Object> queryMap) {
		return researchProjectAuditingMapper.queryResearchProjectAuditingList(queryMap);
	}

	@Override
	public List<Department> getDepartList() {
		
		return researchProjectAuditingMapper.getDepartList();
	}

	@Override
	public List<TeachingGroup> getTeachList() {
		return researchProjectAuditingMapper.getTeachList();
	}

}
